package view;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JLabel;
import javax.swing.JTextField;

import javax.swing.WindowConstants;
import javax.swing.SwingUtilities;

import controller.Sistema;


/**
* This code was edited or generated using CloudGarden's Jigloo
* SWT/Swing GUI Builder, which is free for non-commercial
* use. If Jigloo is being used commercially (ie, by a corporation,
* company or business for any purpose whatever) then you
* should purchase a license for each developer using Jigloo.
* Please visit www.cloudgarden.com for details.
* Use of Jigloo implies acceptance of these licensing terms.
* A COMMERCIAL LICENSE HAS NOT BEEN PURCHASED FOR
* THIS MACHINE, SO JIGLOO OR THIS CODE CANNOT BE USED
* LEGALLY FOR ANY CORPORATE OR COMMERCIAL PURPOSE.
*/
public class AltaLineaTitular extends javax.swing.JFrame {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	private AltaLineaTitular instancia; 
	private JButton Cancelar;
	private JButton Aceptar;
	private JTextField NombreLinea;
	private JLabel NumeroPlan;
	private JTextField DNIUsuario1;
	private JLabel DNIusuario;
	/**
	* Auto-generated main method to display this JFrame
	*/
	public static void main(String[] args) {
		SwingUtilities.invokeLater(new Runnable() {
			public void run() {
				AltaLineaTitular inst = new AltaLineaTitular();
				inst.setLocationRelativeTo(null);
				inst.setVisible(true);
			}
		});
	}
	
	public AltaLineaTitular() {
		super();
		initGUI();
		instancia=this;
		this.setTitle("Alta Linea Titular");
	}
	
	private void initGUI() {
		try {
			setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
			getContentPane().setLayout(null);
			{
				DNIusuario = new JLabel();
				getContentPane().add(DNIusuario);
				DNIusuario.setText("DNI Usuario");
				DNIusuario.setBounds(50, 41, 116, 16);
			}
			{
				DNIUsuario1 = new JTextField();
				getContentPane().add(DNIUsuario1);
				DNIUsuario1.setBounds(190, 38, 141, 23);
			}
			{
				NumeroPlan = new JLabel();
				getContentPane().add(NumeroPlan);
				NumeroPlan.setText("Nombre Linea");
				NumeroPlan.setBounds(50, 87, 116, 16);
			}
			{
				NombreLinea = new JTextField();
				getContentPane().add(NombreLinea);
				NombreLinea.setBounds(190, 84, 141, 23);
			}
			{
				Aceptar = new JButton();
				getContentPane().add(Aceptar);
				Aceptar.setText("Aceptar");
				Aceptar.setBounds(70, 152, 87, 30);
				Aceptar.addActionListener(new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent arg0) {
						if (HelperTest.validarLinea(DNIUsuario1.getText(),NombreLinea.getText())) {
							try {
								if  (Sistema.getInstance().altaLineaTitular(DNIUsuario1.getText(),NombreLinea.getText())==false){
									HelperTest.showMessage("No se pudo dar de alta la linea");
								}
							} catch (Exception e) {
								// TODO Auto-generated catch block
								e.printStackTrace();
							}
							limpiarCampos();	
						}
					}

					
				});
			}
			{
				Cancelar = new JButton();
				getContentPane().add(Cancelar);
				Cancelar.setText("Cancelar");
				Cancelar.setBounds(190, 152, 87, 30);
				Cancelar.addActionListener(new ActionListener() {
					
					@Override
					public void actionPerformed(ActionEvent e) {
						Menu app = new Menu();
						app.setLocationRelativeTo(null);
						app.setVisible(true);
						instancia.dispose();
					}
				});
			}
			pack();
			setSize(400, 300);
		} catch (Exception e) {
		    //add your error handling code here
			e.printStackTrace();
		}
	}
	private void limpiarCampos() {
		// TODO Auto-generated method stub
		DNIUsuario1.setText("");
		NombreLinea.setText("");
	}

}
